﻿using Anke.SHManage.MSSQLDAL.TJDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class LS_GRBLSHYPXModeWebForm : System.Web.UI.Page
    {
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }

        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();
        }
        private void InitPage()
        {
            reportName = Request.QueryString["ReportName"];
            ViewState["reportName"] = reportName;

            this.StartDate.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 07:30:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 07:30:00");
            BindReportDataSource();
        }
        protected void BindReportDataSource()
        {
            //DateTime dateStart = Convert.ToDateTime(this.StartDate.Text);
            //DateTime dateEnd = Convert.ToDateTime(this.EndDate.Text);
            DateTime dateStart = Convert.ToDateTime(this.StartDate.Text);
            DateTime dateEnd = Convert.ToDateTime(this.EndDate.Text);
            string start1 = dateStart.ToString();
            string end1 = dateEnd.ToString();

            string centerID = Convert.ToString(this.Center.Text);
            string stationID = Convert.ToString(this.Station.Text);
            string workID = Convert.ToString(this.workID.Text);
            //string txtCenterAuditResult = Convert.ToString(this.txtCenterAuditResult.Text);

            this.ReportViewer1.LocalReport.DataSources.Clear();
        //  this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/LS_GRBLSHYPX.rdlc");
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("StartTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("EndTime", end1);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });


            TJDAL dal = new TJDAL();
            switch (reportName)
            {
                case "LS_GRBLSHYPX.rdlc":

                    DataTable dt = dal.Get_LS_GRBLSHYPX(dateStart, dateEnd, centerID, stationID, workID);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
                    break;
                case "LS_JJKGRBLSHYPX.rdlc":
                    DataTable dt1 = dal.Get_LS_JJKGRBLSHYPX(dateStart, dateEnd,centerID,stationID,workID);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", dt1));
                    break;
                default:
                    break;
            }

            this.ReportViewer1.LocalReport.Refresh();
        }

    }
}